home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / changebar / changebar.sty < prev    next >
Text File  |  1994-04-21  |  12KB  |  354 lines

  1. %% 
  2. %% This is file `changebar.sty', generated on <1993/10/11> 
  3. %% with the docstrip utility (2.1e).
  4. %% 
  5. %% The original source file was `changebar.doc'.
  6. %% 
  7. %% 
  8. %% IMPORTANT NOTICE:
  9. %% You are not allowed to distribute this file.
  10. %% For distribution of the original source see
  11. %% the copyright notice in the file changebar.doc.
  12. %% 
  13. %%% ====================================================================
  14. %%%  @LaTeX-style-file{
  15. %%%     author          = "Braams J.L.",
  16. %%%     version         = "3.1b",
  17. %%%     date            = "11 October 1993",
  18. %%%     time            = "09:12:24 MET",
  19. %%%     filename        = "changebar.doc",
  20. %%%     address         = "PTT Research
  21. %%%                        St. Paulusstraat 4
  22. %%%                        2264 XZ Leidschendam
  23. %%%                        The Netherlands",
  24. %%%     telephone       = "(70) 3325051",
  25. %%%     FAX             = "(70) 3326477",
  26. %%%     checksum        = "51434 1276 6008 47620",
  27. %%%     email           = "J.L.Braams@research.ptt.nl (Internet)",
  28. %%%     codetable       = "ISO/ASCII",
  29. %%%     keywords        = "",
  30. %%%     supported       = "yes",
  31. %%%     abstract        = "",
  32. %%%     docstring       = "THis LaTeX document style option implements
  33. %%%                        changebars for LaTeX documents. It supports
  34. %%%                        various printer drivers through a selection
  35. %%%                        mechanism.
  36. %%%
  37. %%%                        The checksum field above contains a CRC-16
  38. %%%                        checksum as the first value, followed by the
  39. %%%                        equivalent of the standard UNIX wc (word
  40. %%%                        count) utility output of lines, words, and
  41. %%%                        characters.  This is produced by Robert
  42. %%%                        Solovay's checksum utility.",
  43. %%%  }
  44. %%% ====================================================================
  45. \def\fileversion{v3.1b}
  46. \def\filedate{11 october 93}
  47. \wlog{Document style option `changebar', \fileversion\space<\filedate>}
  48. \chardef\atcatcode=\catcode`\@
  49. \catcode`\@=11\relax
  50. \def\cb@maxpoint{80}
  51. \def\cb@minpoint{1}
  52. \def\cb@nil{0}
  53. \newcount\cb@nextpoint
  54. \cb@nextpoint=\cb@minpoint
  55. \newcount\cb@currentpoint
  56. \newcount\cb@page
  57. \newcount\cb@pagecount
  58. \cb@pagecount=0
  59. \newif\ifouterbars \outerbarsfalse
  60. \newdimen\cb@odd
  61. \newdimen\cb@even
  62. \def\cb@positions{%
  63.   \global\cb@odd =\hoffset
  64.   \global\advance\cb@odd by \oddsidemargin
  65.   \ifouterbars
  66.     \global\advance\cb@odd by \textwidth
  67.     \global\advance\cb@odd by \changebarsep
  68.     \global\advance\cb@odd by 0.5\changebarwidth
  69.   \else
  70.     \global\advance\cb@odd by -\changebarsep
  71.     \global\advance\cb@odd by -0.5\changebarwidth
  72.   \fi
  73.   \global\cb@even =\hoffset
  74.   \global\advance\cb@even by \evensidemargin
  75.   \if@twoside
  76.     \ifouterbars
  77.       \global\advance\cb@even by -\changebarsep
  78.       \global\advance\cb@even by -0.5\changebarwidth
  79.     \else
  80.       \global\advance\cb@even by \textwidth
  81.       \global\advance\cb@even by \changebarsep
  82.       \global\advance\cb@even by 0.5\changebarwidth
  83.     \fi
  84.   \else
  85.     \ifouterbars
  86.       \global\advance\cb@even by \textwidth
  87.       \global\advance\cb@even by \changebarsep
  88.       \global\advance\cb@even by 0.5\changebarwidth
  89.     \else
  90.       \global\advance\cb@even by -\changebarsep
  91.       \global\advance\cb@even by -0.5\changebarwidth
  92.     \fi
  93.   \fi}
  94. {\catcode`\p=12\catcode`\t=12 \gdef\cb@removedim#1pt{#1}}
  95. \def\driver#1{%
  96.   \bgroup\edef\next{\def\noexpand\tempa{#1}}%
  97.     \uppercase\expandafter{\next}%
  98.     \def\LN{DVITOLN03}%
  99.     \def\DVItoPS{DVITOPS}%
  100.     \def\DVIPS{DVIPS}%
  101.     \def\emTeX{EMTEX}%
  102.     \global\chardef\cb@driver@setup=0\relax
  103.     \ifx\tempa\LN      \global\chardef\cb@driver@setup=0\fi
  104.     \ifx\tempa\DVItoPS \global\chardef\cb@driver@setup=1\fi
  105.     \ifx\tempa\DVIPS   \global\chardef\cb@driver@setup=2\fi
  106.     \ifx\tempa\emTeX   \global\chardef\cb@driver@setup=3\fi
  107.   \egroup}
  108. {\def\do{\noexpand\do\noexpand}
  109.  \xdef\@preamblecmds{\@preamblecmds \do\driver}
  110. }
  111. \def\cb@setup@specials{%
  112. \ifcase\cb@driver@setup
  113.   \def\cb@defpoint##1##2{\special{ln03:defpoint \the##1(\the##2,)}}
  114.   \def\cb@connect##1##2##3{%
  115.     \special{ln03:connect \the##1\space\space \the##2\space \the##3}}
  116.   \def\cb@resetpoints{%
  117.     \special{ln03:resetpoints \cb@minpoint \space\cb@maxpoint}}
  118. \or
  119.   \def\cb@defpoint##1##2{%
  120.     \special{dvitops: inline
  121.                 \expandafter\cb@removedim\the##2\space 6.5536 mul\space
  122.                 /CBarX\the##1\space exch def currentpoint exch pop
  123.                 /CBarY\the##1\space exch def}}
  124.   \def\cb@connect##1##2##3{%
  125.     \special{dvitops: inline
  126.                 gsave \thechangebargrey\space 100 div setgray
  127.                 \expandafter\cb@removedim\the##3\space 6.5536 mul\space
  128.                 CBarX\the##1\space\space CBarY\the##1\space\space moveto
  129.                 CBarX\the##2\space\space CBarY\the##2\space\space lineto
  130.                 stroke grestore}}
  131.   \let\cb@resetpoints\relax
  132. \or
  133.   \def\cb@defpoint##1##2{%
  134.      \special{ps:
  135.                 \expandafter\cb@removedim\the##2\space
  136.                 Resolution\space mul\space 72.27\space div\space
  137.                 /CBarX\the##1\space exch def currentpoint exch pop
  138.                 /CBarY\the##1\space exch def}}
  139.     \def\cb@connect##1##2##3{%
  140.       \special{ps:
  141.                 gsave \thechangebargrey\space 100 div setgray
  142.                 \expandafter\cb@removedim\the##3\space
  143.                 Resolution\space mul\space 72.27\space div\space
  144.                 setlinewidth
  145.                 CBarX\the##1\space\space CBarY\the##1\space\space moveto
  146.                 CBarX\the##2\space\space CBarY\the##2\space\space lineto
  147.                 stroke grestore}}
  148.     \let\cb@resetpoints\relax
  149. \or
  150.   \typeout{Changebar Warning: changebars only supported for v1.5+ of dvidrv}%
  151.   \def\cb@defpoint##1##2{\special{em:point \the##1,\the##2}}%
  152.   \def\cb@connect##1##2##3{\special{em:line \the##1,\the##2,\the##3}}%
  153.   \let\cb@resetpoints\relax
  154. \else
  155.   \typeout{Changebar Warning: changebars not supported in unknown setup}
  156.   \def\cb@defpoint##1##2{}%
  157.   \def\cb@connect##1##2##3{}%
  158.   \let\cb@resetpoints\relax
  159. \fi
  160. \global\let\cb@setup@specials\relax}
  161. \def\cbstart{\@ifnextchar [{\cb@start}{\cb@start[\changebarwidth]}}
  162. \def\cbend{\cb@end}
  163. \def\cbdelete{\@ifnextchar [{\cb@delete}{\cb@delete[\deletebarwidth]}}
  164. \def\cb@delete[#1]{\vbox to 0pt{\vss\cb@start[#1]\vskip #1\cb@end}}
  165. \def\changebar{\@ifnextchar [{\cb@start}{\cb@start[\changebarwidth]}}%
  166. \def\endchangebar{\cb@end}
  167. \def\nochangebars{\def\cb@start[##1]{}%
  168.                   \def\cb@delete[##1]{}%
  169.                   \let\cb@end\relax}
  170. \newlength{\changebarwidth}
  171. \setlength{\changebarwidth}{2pt}
  172. \newlength{\deletebarwidth}
  173. \setlength{\deletebarwidth}{4pt}
  174. \newlength{\changebarsep}
  175. \setlength{\changebarsep}{30pt}
  176. \newcounter{changebargrey}
  177. \setcounter{changebargrey}{65}
  178. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  179. \def\cb@start[#1]{\cb@currentpoint=\cb@nextpoint
  180.         \@tempdima=#1\relax                             % for \cb@push
  181.         \cb@push\cb@currentlist
  182.         \ifvmode \cb@setBeginPoint\cb@currentpoint
  183.         \else \vbox to 0pt{\vskip -\ht\strutbox         %jump up a line to
  184.         \cb@setBeginPoint\cb@currentpoint               %set point
  185.         \vskip \ht\strutbox}\fi
  186.         \cb@writeAux\cb@advancePoint}
  187. \def\cb@advancePoint{%
  188.   \global\advance\cb@nextpoint by 2\relax
  189.   \ifnum\cb@nextpoint>\cb@maxpoint
  190.     \global\cb@nextpoint=\cb@minpoint\relax
  191.   \fi}
  192. \def\cb@end{%
  193.   \cb@pop\cb@currentlist
  194.   \ifnum\cb@currentpoint=\cb@nil
  195.     \typeout{Changebar Warning: Badly nested changebars;
  196.                                 Expect erroneous results}%
  197.   \else
  198.     \cb@setEndPoint\cb@currentpoint
  199.     \advance\cb@currentpoint by1\cb@writeAux
  200.   \fi}
  201. \def\cb@setBeginPoint#1{%
  202.   \ifodd\cb@pagecount
  203.     \cb@defpoint{#1}{\cb@even}%
  204.   \else
  205.     \cb@defpoint{#1}{\cb@odd}%
  206.   \fi}
  207. \def\cb@setEndPoint#1{%
  208.   \@tempcnta=#1\advance\@tempcnta by1\relax
  209.   \ifodd\cb@pagecount
  210.     \cb@defpoint{\@tempcnta}{\cb@even}%
  211.   \else
  212.     \cb@defpoint{\@tempcnta}{\cb@odd}%
  213.   \fi
  214.   \cb@connect{#1}{\@tempcnta}{\@tempdima}}%
  215. \def\cb@writeAux{%
  216.   \if@filesw
  217.     \begingroup
  218.       \edef\point{\the\cb@currentpoint}%
  219.       \edef\level{\the\@tempdima}%
  220.       \let\the=0%
  221.       \edef\cb@temp{\write\@auxout
  222.           {\string\cb@barpoint{\point}{\the\cb@pagecount}{\level}}}%
  223.       \cb@temp
  224.     \endgroup
  225.   \fi}
  226. \let\cb@makecol=\@makecol
  227. \def\@makecol{%
  228.   \setbox\@cclv=\vbox{\cb@resetpoints\cb@beginSaves\unvbox\@cclv}%
  229.   \gdef\cb@beginSaves{}
  230.   \global\advance\cb@pagecount by 1\relax
  231.   \cb@buildActive\cb@processActive
  232.   \cb@makecol}
  233. \def\cb@processActive{%
  234.   \cb@pop\cb@spanlist
  235.   \ifnum\cb@currentpoint=\cb@nil
  236.   \else
  237.     \setbox\@cclv=\vbox{\unvbox\@cclv\advance\cb@pagecount by -1\relax
  238.                         \cb@setEndPoint\cb@currentpoint}%
  239.     \cb@saveBeginPoint\cb@currentpoint
  240.     \cb@push\cb@history
  241.     \cb@processActive
  242.   \fi}
  243. \def\cb@saveBeginPoint#1{%
  244.   \ifodd\cb@pagecount
  245.     \xdef\cb@beginSaves{\cb@defpoint{#1}{\cb@even}\cb@beginSaves}%
  246.   \else
  247.     \xdef\cb@beginSaves{\cb@defpoint{#1}{\cb@odd}\cb@beginSaves}%
  248.   \fi}
  249. \def\cb@beginSaves{}                % initially empty
  250. \def\cb@buildActive{\cb@initlist\cb@spanlist\cb@pushNextActive}
  251. \def\cb@pushNextActive{%
  252.   \cb@pop\cb@history
  253.   \ifnum\cb@currentpoint=\cb@nil
  254.   \else
  255.     \ifnum\cb@page>\cb@pagecount
  256.       \cb@push\cb@history
  257.     \else
  258.       \ifodd\cb@currentpoint
  259.         \cb@push\cb@spanlist
  260.       \else
  261.         \cb@pop\cb@spanlist
  262.       \fi
  263.       \cb@pushNextActive
  264.     \fi
  265.   \fi}
  266. \def\cb@initlist#1{\xdef#1{}}
  267. \cb@initlist\cb@history         % the history list; initially empty
  268. \cb@initlist\cb@spanlist        % list of bars spanning current page
  269. \cb@initlist\cb@currentlist     % used to implement nesting without using
  270.                                 % TeX grouping
  271.  
  272. \newwrite\cb@write              % file for history list
  273. \newread\cb@read
  274. \immediate\openout\cb@write=\jobname.cb % open for building of history list
  275. \def\cb@pop#1{%
  276.   \ifx #1\cb@history
  277.     \ifeof\cb@read
  278.     \else
  279.       {\endlinechar=-1\read\cb@read to\@temp
  280.        \xdef\cb@history{\cb@history\@temp}%
  281.       }%
  282.     \fi
  283.   \fi
  284.   \ifx#1\@empty
  285.     \cb@currentpoint=\cb@nil\cb@page=0\relax
  286.   \else
  287.     \expandafter\cb@carcdr#1e#1%
  288.   \fi}
  289. \def\cb@carcdr#1n#2p#3l#4e#5{%
  290.   \cb@currentpoint=#1\cb@page=#2\relax\@tempdima=#3\xdef#5{#4}}
  291. \def\cb@push#1{%
  292.   \xdef#1{\the\cb@currentpoint n\the\cb@page p\the\@tempdima l#1}}
  293. \def\cb@barpoint#1#2#3{\immediate\write\cb@write{#1n#2p#3l}}
  294. \let\cb@document=\document
  295. \def\document{\cb@document
  296.               \cb@setup@specials
  297.               \cb@positions
  298.               \immediate\closeout\cb@write
  299.               \immediate\openin\cb@read=\jobname.cb}
  300. \let\cb@enddocument\enddocument
  301. \def\enddocument{\clearpage\cb@initlist\cb@history
  302.    \immediate\closein\cb@read\immediate\openin\cb@read=\jobname.cb%
  303.    \let\cb@barpoint=\cb@checkHistory\cb@enddocument}
  304. \def\cb@checkHistory#1#2#3{\cb@pop\cb@history
  305.         \ifnum #1=\cb@currentpoint\relax
  306.             \ifnum #2=\cb@page\relax  % do nothing
  307.             \else \cb@error           % page numbers mismatched
  308.             \fi
  309.         \else \cb@error               % point numbers mismatched
  310.         \fi}
  311. \def\cb@error{%
  312.   \message{Changebar Warning: Changebar info has changed. %
  313.                               Rerun to get right.}
  314.   \gdef\cb@checkHistory##1##2##3{}%
  315.   \let\cb@barpoint=\cb@checkHistory}
  316. \let\cb@endfloat=\end@float
  317. \def\end@float{%
  318.   \cb@pop\cb@currentlist
  319.   \ifnum\cb@currentpoint=\cb@nil
  320.   \else
  321.     \cb@push\cb@currentlist
  322.     \global\@tempdima=\@tempdima
  323.     \egroup
  324.     \global\setbox\@currbox=%
  325.         \vbox\bgroup\cb@start[\@tempdima]\unvbox\@currbox\cb@end
  326.   \fi
  327.   \cb@endfloat}
  328. \let\endfigure=\end@float       % need to rebind these to new def
  329. \let\endtable=\end@float
  330. \let\cb@footnote=\@footnotetext
  331. \long\def\@footnotetext#1{%
  332.   \cb@pop\cb@currentlist
  333.   \ifnum\cb@currentpoint=\cb@nil
  334.     \cb@footnote{#1}%
  335.   \else
  336.     \cb@push\cb@currentlist
  337.     \edef\cb@temp{\the\@tempdima}%
  338.     \cb@footnote{\cb@start[\cb@temp]#1\cb@end}%
  339.   \fi}
  340. \let\cb@mpfootnote=\@mpfootnotetext
  341. \long\def\@mpfootnotetext#1{%
  342.   \cb@pop\cb@currentlist
  343.   \ifnum\cb@currentpoint=\cb@nil
  344.     \cb@mpfootnote{#1}%
  345.   \else
  346.     \cb@push\cb@currentlist
  347.     \edef\cb@temp{\the\@tempdima}%
  348.     \cb@mpfootnote{\cb@start[\cb@temp]#1\cb@end}%
  349.   \fi}
  350. \catcode`\@=\atcatcode \let\atcatcode\relax
  351. \endinput
  352. %% 
  353. %% End of file `changebar.sty'.
  354.